using System.Linq;
using System.Web.Mvc;
using Quickie.Models;
using Quickie.Models.IoC;
using Quickie.Models.Data;
using Quickie.Models.Entities;
using Quickie.Models.ViewModel;
using Quickie.Models.Interfaces;

namespace Quickie.Controllers
{
    [Authorize(Roles = "Administrator,Korisnik")]
    public class CategoryController : Controller
    {
        private IRepository<Category> categories;

        public CategoryController(IRepository<Category> categories)
        {
            this.categories = categories;
        }

        public ActionResult MainMenu()
        {
            var viewModel = new MenuLevelViewData();
            viewModel.Categories = categories.GetAll().Where(x => x.ParentID == null).ToList();

            return View(viewModel);
        }

        public ActionResult SubMenu(int idParent)
        {
            var viewModel = new MenuLevelViewData();
            viewModel.Categories = categories.GetAll().Where(x => x.ParentID == idParent).ToList();

            return View(viewModel);
        }

    }
}
